package com.bwie.controller;

import com.bwie.pojo.TbProd;
import com.bwie.pojo.TbProdAtta;
import com.bwie.service.TbProdInfoService;
import com.bwie.service.TbProdService;
import com.bwie.utils.R;
import com.bwie.vo.ProdPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description :
 * @Author QiHainan
 * @Create 2025/6/24 9:58
 * @Version 1.0
 */
@RestController
@RequestMapping("/shop/prod")
public class ProdController {

    @Autowired
    TbProdService tbProdService;
    @Autowired
    TbProdInfoService tbProdInfoService;

    /**
     * 分页获取商品列表
     * @return
     */
    @PostMapping("/getProdList")
    public R getProdList(@RequestBody ProdPageVo prodPageVo){
        return tbProdService.getProdList(prodPageVo);
    }

    /**
     * 添加商品
     * @param tbProd
     * @return
     */
    @PostMapping("/addProd")
    public R addProd(@RequestBody @Validated TbProd tbProd){
        return tbProdService.addProd(tbProd);
    }

    /**
     * 添加商品附件
     * @param tbProdAtta
     * @return
     */
    @PostMapping("/addProdAtta")
    public R addProdAtta(@RequestBody TbProdAtta tbProdAtta){
        return tbProdService.addProdAtta(tbProdAtta);
    }

    /**
     * 批量删除商品
     * @param ids
     * @return
     */
    @PostMapping("/deleteBatchProd")
    public R deleteBatchProd(@RequestBody List<Integer> ids){
        return tbProdService.deleteBatchProd(ids);
    }

    /**
     * 单个删除商品
     * @param id
     * @return
     */
    @PostMapping("/deleteProd/{id}")
    public R deleteProd(@PathVariable("id") Integer id){
        return tbProdService.deleteProd(id);
    }

    /**
     * 获取商品信息列表
     * @return
     */
    @PostMapping("/getProdInfoList")
    public R getProdInfoList(){
        return tbProdInfoService.getProdInfoList();
    }

    /**
     * 从Es获取商品
     * @param prodPageVo
     * @return
     */
    @PostMapping("/getProdFromEs")
    public R getProdFromEs(@RequestBody ProdPageVo prodPageVo){
        return tbProdService.getProdFromEs(prodPageVo);
    }
}
